<template>
  <div class="settings">
    <van-nav-bar safe-area-inset-top placeholder :title="$t('BasicSetting')" left-arrow fixed @click-left="onClickLeft" />
    <van-pull-refresh v-model="isLoading" :pulling-text="$t('PullingText')" :loosing-text="$t('PullingText')" :success-text="$t('refreshSuccee')" @refresh="onRefresh">
      <van-collapse class="marginTop15" v-model="activeNames">
        <van-collapse-item :title="$t('Datetime')" name="1">
          <datetimePTVue :times="LocalArr.datetimes"></datetimePTVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('Language')" name="2">
          <languagePTVue :columns="langArr" :setValue="LocalArr.lang" :reg="71"></languagePTVue>
        </van-collapse-item>
        <van-collapse-item title="Self Test" name="3" v-if="safety==24">
          <van-cell title="Self Test Start" is-link @click="goSelftTest(1)" />
          <van-cell title="Self Test Results" is-link @click="goSelftTest(2)" />
        </van-collapse-item>
      </van-collapse>
    </van-pull-refresh>
  </div>
</template>

<script>
import datetimePTVue from '../../../components/DateTime/BDDateTimePT'
import languagePTVue from '../../../components/Language/BDLanguagePT'
export default {
  components:{
    datetimePTVue,
    languagePTVue
  },
  data(){
    return {
      isLoading:false,
      activeNames:[],
      safety:sessionStorage.getItem('safety'),
      langArr:[this.$t('English'),this.$t('German'),this.$t('Polish'),this.$t('French'),this.$t('Portuguese')],
      LocalArr:{
        datetimes:'',
        lang:''
      }
    }
  },
  methods: {
    onClickLeft(){
      this.$router.push({path:'/bdsetting'});
    },
    goSelftTest(num){
      sessionStorage.setItem('setFrom','/bdx1boostairminibasicPT');
      if(num==1){
        this.$router.push({path:'/bdteststart'});
      }else{
        this.$router.push({path:'/bdtestresult'});
      }
    },
    async getData(){
      this.comm.loadingShow();
      let datas = await this.SETAPI.LocalIn({'optType':'ReadSetData','pwd':sessionStorage.getItem('bdPwd')});
      if(datas!=null||datas!=undefined){
        let dataArr = datas;
        this.safety=dataArr[4];
        sessionStorage.setItem('safety',this.safety);
        let year=dataArr[29];
        let month=dataArr[28]>=10?dataArr[28]:"0"+dataArr[28];
        let day=dataArr[27]>=10?dataArr[27]:"0"+dataArr[27];
        let hour=dataArr[26]>=10?dataArr[26]:"0"+dataArr[26];
        let minute=dataArr[25]>=10?dataArr[25]:"0"+dataArr[25];
        this.LocalArr.datetimes=`${year+2000}-${month}-${day} ${hour}:${minute}`;
        this.LocalArr.lang=dataArr[67];
      }else{
        this.comm.tipsShow('InvNoResponse');
      }
    },
    onRefresh(){
      this.isLoading = false;
      for(let i in this.LocalArr){
        this.LocalArr[i]='';
      }
      this.getData();
    }
  },
  mounted(){
    setTimeout(()=>{
      this.getData();
    },1000);
  }
}
</script>

<style scoped lang="less">

</style>
